﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace QuanLyKhachSan
{
    public partial class UC_GiaPhong_TheoGio_Edit : System.Web.UI.UserControl
    {
        private int PhongID;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.Request.QueryString["PhongID"] != null)
            {
                PhongID = int.Parse(this.Request.QueryString["PhongID"].ToString());
                string status = Gio_PhongBLL.Gio_Phong_KiemTraStatus(PhongID);
                if (status == "")
                {
                    cbxLoaiGia.Items[1].Visible = false;
                    cbxLoaiGia.Items[2].Visible = false;
                }
                else {
                    if (status.IndexOf("GiaGoc") >= 0)
                    {
                        cbxLoaiGia.Items[0].Enabled = false;
                    }
                    if (status.IndexOf("GiaCuoi") >= 0)
                    {
                        cbxLoaiGia.Items[2].Enabled = false;
                    }
                }
            }
        }
        protected void cmdOK_Click(object sender, EventArgs e)
        {
            try
            {                
                string GioPhongName =  txtGio.Text;
                int PhanTram = 0;
                decimal GiaTien=0;
                string Status = cbxLoaiGia.SelectedValue;
                if (Status == "GiaGoc")
                {
                    PhanTram = 0;
                    GiaTien = decimal.Parse(txtGia.Text.ToString());
                }
                else
                {
                    //Lay Gia Goc
                    decimal GiaGoc = Gio_PhongBLL.Gio_Phong_GiaGoc(PhongID);
                    if (cbxCachTinh.SelectedValue == "0")
                    {
                        //Tinh Truc Tiep Bang Tien==>Phan Tram
                        GiaTien = decimal.Parse(txtGia.Text.ToString());
                        PhanTram = (int)(GiaTien * 100 / GiaGoc);
                    }
                    else
                    { 
                        //Tinh Bang Phan Tram ==>Gia Tien
                        PhanTram = int.Parse(txtPhanTram.Text.ToString());
                        GiaTien = (GiaGoc * PhanTram) / 100;
                    }
                }
                Gio_PhongBLL.Gio_Phong_Add(PhongID, GioPhongName, PhanTram, GiaTien, Status);
            }
            catch (Exception ex)
            {                
                Response.Write(ex.StackTrace.ToString());
            }
        }
}
}